//
//  ZallTextImageControl.m
//  ZJS
//
//  Created by so on 16/7/11.
//  Copyright © 2016年 zall. All rights reserved.
//

#import "ZallTextImageControl.h"

@implementation ZallTextImageControl
@synthesize textLabel = _textLabel;
@synthesize imageView = _imageView;

#pragma mark - life cycle
- (void)dealloc {
    
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        _contentInsets = UIEdgeInsetsZero;
        _textInsets = UIEdgeInsetsZero;
        _imageInsets = UIEdgeInsetsZero;
        [self addSubview:self.textLabel];
        [self addSubview:self.imageView];
    }
    return (self);
}
#pragma mark -

#pragma mark - override
- (void)layoutSubviews {
    [super layoutSubviews];
    self.imageView.frame = UIEdgeInsetsInsetRect(UIEdgeInsetsInsetRect(self.bounds, self.contentInsets), self.imageInsets);
    self.textLabel.frame = UIEdgeInsetsInsetRect(UIEdgeInsetsInsetRect(self.bounds, self.contentInsets), self.textInsets);
}
#pragma mark -

#pragma mark - setter
- (void)setImageInsets:(UIEdgeInsets)imageInsets {
    [self willChangeValueForKey:@"imageInsets"];
    _imageInsets = imageInsets;
    [self didChangeValueForKey:@"imageInsets"];
    [self setNeedsLayout];
}

- (void)setTextInsets:(UIEdgeInsets)textInsets {
    [self willChangeValueForKey:@"textInsets"];
    _textInsets = textInsets;
    [self didChangeValueForKey:@"textInsets"];
    [self setNeedsLayout];
}
#pragma mark -

#pragma mark - getter
- (UIImageView *)imageView {
    if(!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.backgroundColor = [UIColor clearColor];
    }
    return (_imageView);
}

- (UILabel *)textLabel {
    if(!_textLabel) {
        _textLabel = [[UILabel alloc] init];
        _textLabel.backgroundColor = [UIColor clearColor];
        _textLabel.font = [UIFont systemFontOfSize:14];
        _textLabel.textAlignment = NSTextAlignmentCenter;
    }
    return (_textLabel);
}
#pragma mark -

@end
